function agent_widget()
{
    cc_flag = 1;
    get_number = 1;

    $("#customer_box_waiting").show();
    $("#customer_box").hide();
    $("#customer_form").hide();
    $("#customer_form_finish").hide();

    $('button').click(
        function(e)
        {
            e.preventDefault();
            mn = document.getElementById("mobile_number").value;
            $("#notice").html('');
            if(this.name == 'submit')
            {
                if(mn != '')
                {
                    $.post(base_url + "ajax/confirm_mobile_number",
                        { mobile_number: mn, log_id: window.li },
                        function(data)
                        {
                            if(!data)
                            {
                                $("#notice").html('Queue number and mobile number do not match');
                            }
                            else
                            {
                                $("#customer_form").hide();
                                $("#customer_form_finish").show();
                                $("#customer_box_waiting").hide();
                                $("#customer_box").show();
                            }
                        }
                    );
                }
                else
                {
                    $("#notice").html('Please enter the mobile number');
                }
            }
            /*
            else if(this.name == 'call')
            {
                $.post(base_url + "ajax/call_number",
                    { log_id: window.li }
                );
                $("#call").attr('disabled', true);
                $("#skip").attr('disabled', false);
                $("#enter").attr('disabled', false);
            }
            */
            else if(this.name == 'skip')
            {
                $.post(base_url + "ajax/skip_queue_number",
                    { log_id: window.li }
                );
                $("#customer_box_waiting").show();
                $("#customer_box").hide();
                window.get_number = 1;
            }
            else if(this.name == 'finish')
            {
                window.closing_code = document.getElementById("closing_code").value;
                $.post(base_url + "ajax/end_service",
                    { log_id: li, closing_code: closing_code }
                );
                $("#customer_box").hide();
                $("#customer_box_waiting").show();
                window.get_number = 1;
            }
            $("#mobile_number").val('');
        }
    );
}

function get_waiting()
{
    if(window.get_number == 1)
    {
        $.post(base_url + "ajax/get_queue_number",
            function(data)
            {
                if(data)
                {
                    window.get_number = 0;
                    $("#service_type").html(data.service_title);
                    $("#queue_number").html(data.service_prefix + pad(data.queue_number, 4));

                    li = data.log_id;
                    si = data.service_id;
                    ts = data.timestart;
/*
                    if(data.call_counter == 0)
                    {
                        $("#call").attr('disabled', false);
                        $("#skip").attr('disabled', true);
                        $("#enter").attr('disabled', true);
                    }
                    else
                    {
                        $("#call").attr('disabled', true);
                        $("#skip").attr('disabled', false);
                        $("#enter").attr('disabled', false);
                    }
*/
                    $.post(base_url + "ajax/get_closing_codes",
                        { service_id: si },
                        function(data)
                        {
                            $("#closing_code").html(data);
                        }
                    );

                    // If service for the queue number is still not being rendered
                    if(ts == 0)
                    {
                        $("#customer_form").show();
                        $("#customer_form_finish").hide();
                    }
                    else
                    {
                        $("#customer_form").hide();
                        $("#customer_form_finish").show();
                    }
                    $("#customer_box_waiting").hide();
                    $("#customer_box").show();
                }
                else
                {
                    $("#customer_box_waiting").show();
                    $("#customer_box").hide();
                }
            }, "json"
        );
    }
}

function get_stats()
{
    $.post(base_url + "ajax/get_agent_stats",
        function(data)
        {
            $("#waiting_stat").html(pad(data.waiting, 4));
            $("#served_stat").html(pad(data.served, 4));
            $("#missed_stat").html(pad(data.missed, 4));
        }, "json"
    );
}